﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Warehouse.Api.Write.AllCation.Command.Checksheet;
using Warehouse.Api.Write.AllCation.Command.Shifing;
using Warehouse.Api.Write.AllCation.Command.Stoking;
using Warehouse.ErrorCode;

namespace Warehouse.Api.Write.Controllers
{
    /// <summary>
    /// 出入库控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class WarehouseStokingController : ControllerBase
    {
        //注册中介者
        public readonly IMediator mediator;

        public WarehouseStokingController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        
        /// <summary>
        /// 添加出入库的信息
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public Task<ApiResult<int>> AddStocking(AddStockingCommand request)
        {
            return mediator.Send(request);
        }
        
        /// <summary>
        /// 删除出入库的命令处理
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public Task<ApiResult<int>> DeleteStocking(DeleteStockingCommand request)
        {
            return mediator.Send(request);
        }
        
        /// <summary>
        /// 出入库更新的方法
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPut]
        [Authorize]
        public Task<ApiResult<int>> UpdaetStocking(UpdaetStockingCommand request)
        {
            return mediator.Send(request);
        }

        /// <summary>
        /// 创建出库记录 - 出入库管理模块
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<ApiResult<int>> CreateOutboundRecord(CreateOutboundRecordCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 创建入库记录 - 出入库管理模块
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<ApiResult<int>> CreateInboundRecord(CreateInboundRecordCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 批量创建出库记录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<ApiResult<List<int>>> CreateBatchOutboundRecords(CreateBatchOutboundRecordsCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 批量创建入库记录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        [Authorize]
        public async Task<ApiResult<List<int>>> CreateBatchInboundRecords(CreateBatchInboundRecordsCommand request)
        {
            return await mediator.Send(request);
        }
    }
}
